package cn.wellwan.service.Impl;

import cn.wellwan.dao.UserMapper;
import cn.wellwan.entity.User;
import cn.wellwan.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    private final Logger LOG = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUserById(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteUserById(Long id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int saveUser(User user) {
        if(user.getId() == null){
            return userMapper.insertSelective(user);
        }
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public List<User> findUserList(User user) {
        return userMapper.selectUserList(user);
    }

    @Override
    public User findUserByOpenId(String openId) {
        return userMapper.selectUserByOpenId(openId);
    }
}
